export class PostResponseDto {
  id: string;
  title: string;
  content: string;
  category: string;
  authorId: string;
  username: string;
  nickname: string;
  avatar: string;
  createdAt: Date;
  viewCount: number;
  commentCount: number;
  likeCount: number;

  constructor(partial: Partial<PostResponseDto>) {
    Object.assign(this, partial);
  }

  static fromEntity(post: any, includeAuthor = true): PostResponseDto {
    const response = new PostResponseDto({
      id: post.id,
      title: post.title,
      content: post.content || '',
      category: post.category || 'other',
      authorId: post.authorId,
      createdAt: post.createdAt || new Date(),
      viewCount: post.viewCount || 0,
      commentCount: post.commentCount || 0,
      likeCount: post.likeCount || 0,
    });

    if (includeAuthor && post.author) {
      response.username = post.author.name || '';
      response.nickname = post.author.nickname || '';
      response.avatar = post.author.avatarUrl || '';
    } else {
      // Default values if author information is not available
      response.username = '未知用户';
      response.nickname = '';
      response.avatar = '';
    }

    return response;
  }
} 